﻿using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace IceDog.JsonDotNet.Model
{
    public class Employee : Person
    {
        public Employee()
        {

        }

        public new string Name { get; set; }
        [JsonProperty(IsReference = true)]
        public Employee Manager { get; set; }

        public string Department { get; set; }
        public string JobTitle { get; set; }
        public string Title { get; set; }

        private List<string> _roles;
        public List<string> Roles
        {
            get
            {
                if (_roles == null)
                {
                    throw new Exception("Roles not loaded!");
                }

                return _roles;
            }
            set { _roles = value; }
        }


        public bool ShouldSerializeManager()
        {
            // don't serialize the Manager property if an employee is their own manager
            return (Manager != this);
        }

        [OnError]
        internal void OnError(StreamingContext _, ErrorContext errorContext)
        {
            errorContext.Handled = true;
        }
    }

}